package com.kotiln.lgc.screenadapterlibrary.method1;

import android.view.View;
import android.widget.LinearLayout;

import com.kotiln.lgc.screenadapterlibrary.MyApplication;

/**
 * @author $
 * @fileName ViewCalculateUtil
 * @date2021/3/12 17:33
 * @describe TODO
 * @desc
 */
public class ViewCalculateUtil {

    //获取调用层传入的值进行设置
    public static void setViewLinearLayoutParam(View view, int width,int height,int topMargin,int bottomMargin,int leftMargin,int rightMargin){
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)view.getLayoutParams();
        if(width!=LinearLayout.LayoutParams.MATCH_PARENT&&width!=LinearLayout.LayoutParams.WRAP_CONTENT){
            layoutParams.width= UIUtils.getInstance(MyApplication.getInstance()).getWidth(width);
        }else{
            layoutParams.width=width;
        }

        if(height!=LinearLayout.LayoutParams.MATCH_PARENT&&height!=LinearLayout.LayoutParams.WRAP_CONTENT){
            layoutParams.height= UIUtils.getInstance(MyApplication.getInstance()).getHeight(height);
        }else{
            layoutParams.height=height;
        }

        //Height:竖向缩放 Width:横向缩放
        layoutParams.topMargin= UIUtils.getInstance(MyApplication.getInstance()).getHeight(topMargin);
        layoutParams.bottomMargin= UIUtils.getInstance(MyApplication.getInstance()).getHeight(bottomMargin);
        layoutParams.leftMargin= UIUtils.getInstance(MyApplication.getInstance()).getWidth(leftMargin);
        layoutParams.rightMargin= UIUtils.getInstance(MyApplication.getInstance()).getWidth(rightMargin);
        view.setLayoutParams(layoutParams);
    }
}
